// modules/conversation/conversation.controller.ts

import { Provide, Inject } from '@midwayjs/core';
import { CoolController, BaseController, BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn, Repository } from 'typeorm';

/**
 * 会话表
 */
@Entity('conversation')
export class ConversationEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'varchar', length: 128, comment: '名称' })
  name: string;

  @Column({ type: 'int', comment: '用户ID' })
  userId: number;

  @Column({ type: 'int', comment: '所属智能体ID' })
  agentId: number;

  @Column({ type: 'int', comment: '所属分站ID' })
  subsiteId: number;

  @CreateDateColumn({ type: 'timestamp', comment: '创建时间' })
  createTime: Date;

  // 新增字段：所属站点ID
  @Column({ type: 'int', comment: '所属站点ID' })
  siteId: number;  // 站点ID
}

/**
 * 会话服务
 */
@Provide()
export class ConversationService extends BaseService {
  @InjectEntityModel(ConversationEntity)
  conversationRepo: Repository<ConversationEntity>;

  // 可添加特殊业务方法
}

/**
 * 会话控制器
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: ConversationEntity,
  service: ConversationService,
})
export class ConversationController extends BaseController {
  @Inject()
  conversationService: ConversationService;

  // 如需自定义接口可在此扩展
  // @Post('/custom')
  // async custom(@Body() body) {
  //   return this.ok(await this.conversationService.someMethod(body));
  // }
}
